<?php
namespace admin\Controller;
use Common\Common\Model;
use Common\Model\jobhunterModel;
use Common\Model\jobhunterObject;
use Common\Model\companyModel;
use Common\Model\companyObject;
use Common\Model\deliveryModel;
use Common\Model\deliveryObject;
use Think\Controller;
class HoutaiController extends Controller {
    /**
     * 用户登录处理
     */
    public function login_action(){
        /** @var companyModel $companyFactory */
        $companyFactory = D('company');
        /** @var companyObject $company */
        $company = $companyFactory->fetchByUsername($_POST['username']);
        if($company == null)
            $this->error('用户不存在！');
        if(!$company->checkPassword($_POST['psw']))
            $this->error('密码不正确！');
        $companyFactory->login($company);
        $this->success('登录成功！', '/Houtai/company');
    }
    /**
     * 用户注册处理
     */
    public function register_action(){
        $Dao = M("company");	// 实例化模型类
        // 构建写入的数据数组
        $data["username"] = $_POST['username'];
        $data["passwords"] = $_POST['psw'];
        $data["title"] = $_POST['gongsiming'];
        $data["contents"] = $_POST['jieshao'];

        // 写入数据
        $db=$Dao->where()->select();
        foreach ($db as $value){
            if($data["username"]==$value['username']){
                $i=1;
            }
        }
        if($i==1){
            $this->success('用户名存在！', '/Houtai/register');
        }
        else{
            if($lastInsId = $Dao->add($data)){
                $this->success('注册成功！', '/Houtai/login');
            }
            else{
                $this->success('注册失败！', '/Houtai/register');
            }
        }
    }
    /**
     * 公司招聘信息处理
     */
    public function recruit_action(){
        $Dao = M("recruit");	// 实例化模型类
        // 构建写入的数据数组
        $data["recruit_id"] = $_POST['recruit_id'];
        $data["occupation"] = $_POST['gangwei'];
        $data["leibie"] = $_POST['leibie'];
        $data["min_money"] = $_POST['minmoney'];
        $data["max_money"] = $_POST['maxmoney'];
        $data["content1"] = $_POST['xiangqing'];
        // 写入数据
        if($lastInsId = $Dao->add($data)){
            $this->success('添加成功！', '/Houtai/company');
        } else {
            $this->error('数据写入错误！');
        }
    }

    /**
     * 公司信息显示
     */
    public function company(){
        $db=D("company");
        $db1=$db->test();
        $data = $db->fetch($db1)->title;
        $this->assign("data",$data);
        $contents = $db->fetch($db1)->contents;
        $this->assign("contents",$contents);
        $username = $db->fetch($db1)->username;
        $this->assign("username",$username);
        $passwords = $db->fetch($db1)->passwords;
        $this->assign("passwords",$passwords);
        $tp=D("recruit");
        $recruit_id=$tp->where('recruit_id='.$db1)->select();
        $this->assign('list',$recruit_id);
        $this->display('company');
    }
    /**
     * 公司信息更改
     */
    public function gongsixinxiupdate(){
        $xinxi = D("company"); // 实例化User对象
        $db1=$xinxi->test();
        // 更改用户的name和email的值
        $data = array('username'=>$_POST['username'],'passwords'=>$_POST['psw'],'title'=>$_POST['title'],'contents'=>$_POST['contents']);
        $xinxi-> where($db1)->setField($data);
        if($lastInsId = $xinxi){
            $this->success('更新成功！', '/Houtai/company');
        } else {
            $this->error('更新失败！');
        }
    }
    /**
     * 招聘信息更改
     */
    public function zhaopinxinxiupdate(){
        $xinxi = D("recruit"); // 实例化User对象
        $db1=$xinxi->test();
        // 更改用户的name和email的值
        $data = array('occupation'=>$_POST['occupation'],'leibie'=>$_POST['leibie'],'min_money'=>$_POST['min_money'],'max_money'=>$_POST['max_money'],'content1'=>$_POST['content1']);
        $xinxi-> where($db1)->setField($data);
        if($lastInsId = $xinxi){
            $this->success('更新成功！', '/Houtai/company');
        } else {
            $this->error('更新失败！');
        }
    }
    /**
    招聘跳转
     */
    public function zhaopin_action()
    {
        $db=D("recruit");
        $db1=$_POST['id'];
        $occupation = $db->fetch($db1)->occupation;
        $this->assign("occupation",$occupation);
        $leibie = $db->fetch($db1)->leibie;
        $this->assign("leibie",$leibie);
        $min_money = $db->fetch($db1)->min_money;
        $this->assign("min_money",$min_money);
        $max_money = $db->fetch($db1)->max_money;
        $this->assign("max_money",$max_money);
        $content1 = $db->fetch($db1)->content1;
        $this->assign("content1",$content1);
        $this->display('zhaopin_action');
    }
    /**
    已回复
     */
    public function yihuifu(){
        $tp=D("delivery");
        $tp1=$tp->test();
        $condition = [
            'reply'=> '已回复',
            'deliver_id'=> $tp1
        ];
        $yi=$tp->where($condition)->select();
        $this->assign('list',$yi);
        $this->display('yihuifu');
    }
    /**
    未回复
     */
    public function weihuifu(){
        $tp=D("delivery");
        $tp1=$tp->test();
        $condition = [
            'reply'=> '未回复',
            'deliver_id'=> $tp1
        ];
        $yi=$tp->where($condition)->select();
        $this->assign('list',$yi);
        $this->display('weihuifu');
    }
    /**
    未回复查看简历
     */
    public function houwei_resume(){
        $tp=D("jobhunter");
        $tp1=$_POST['jobhunter1'];
        $yi=$tp->where(['username'=>$tp1])->find();
        $db=D("resume");
        $db1=$db->where(['id'=>$yi['id']])->find();
        $xingming = $db1['xingming'];
        $this->assign("xingming",$xingming);
        $political = $db1['political'];
        $this->assign("political",$political);
        $birthday = $db1['birthday'];
        $this->assign("birthday",$birthday);
        $phone = $db1['phone'];
        $this->assign("phone",$phone);
        $email = $db1['email'];
        $this->assign("email",$email);
        $intention = $db1['intention'];
        $this->assign("intention",$intention);
        $school = $db1['school'];
        $this->assign("school",$school);
        $education = $db1['education'];
        $this->assign("education",$education);
        $gerenpingjia = $db1['gerenpingjia'];
        $this->assign("gerenpingjia",$gerenpingjia);
        $this->display('houwei_resume');
    }
    /**
    已回复查看简历
     */
    public function hou_resume(){
        $tp=D("jobhunter");
        $tp1=$_POST['jobhunter1'];
        $yi=$tp->where(['username'=>$tp1])->find();
        $db=D("resume");
        $db1=$db->where(['id'=>$yi['id']])->find();
        $xingming = $db1['xingming'];
        $this->assign("xingming",$xingming);
        $political = $db1['political'];
        $this->assign("political",$political);
        $birthday = $db1['birthday'];
        $this->assign("birthday",$birthday);
        $phone = $db1['phone'];
        $this->assign("phone",$phone);
        $email = $db1['email'];
        $this->assign("email",$email);
        $intention = $db1['intention'];
        $this->assign("intention",$intention);
        $school = $db1['school'];
        $this->assign("school",$school);
        $education = $db1['education'];
        $this->assign("education",$education);
        $gerenpingjia = $db1['gerenpingjia'];
        $this->assign("gerenpingjia",$gerenpingjia);
        $this->display('hou_resume');
    }
    /**
    已回复查看简历
     */
    public function weihuifu_yihuifu(){
        $db=D("resume");
        $t1=$_POST['xingming'];
        $db1=$db->where(['xingming'=>$t1])->find();
        $Dao=D("jobhunter");
        $Dao1=$Dao->where(['id'=>$db1['id']])->find();
        $tp=D("delivery");
        $data = array('reply'=>'已回复');
        $tp-> where(['jobhunter1'=>$Dao1['username']])->setField($data);
        if($lastInsId = $tp){
            $this->success('更新成功！', '/Houtai/company');
        } else {
            $this->error('更新失败！');
        }
    }
}